 
<header>
    <div class="row b-b m-l-none m-r-none bg-white-only">
        <div class="col-sm-4">
            <h3 class="m-t m-b-none">Dashboard</h3>
            <p class="block text-muted">Welcome to your membership home!</p>
        </div>
        <div class="col-sm-8">
            <!-- MINI STATS - Review before deleting permanently
                <div class="clearfix m-t-lg m-b-sm pull-right pull-none-xs">
                    <div class="pull-left">                  
                        <div class="pull-left m-r-xs">
                            <span class="block">Users <span class="badge up bg-danger">+5</span></span>                    
                            <span class="h4">432k</span>
                            <i class="fa fa-level-up text-success"></i>
                        </div>
                        <div class="clear">
                            <div class="sparkline inline" data-type="bar" data-height="35" data-bar-width="4" data-bar-spacing="2" data-stacked-bar-color="['#afcf6f', '#eee']">5:5,8:4,12:5,10:6,11:7,12:2,8:6</div>
                        </div>
                    </div>
                    <div class="pull-left m-l-lg">
                        <div class="pull-left m-r-xs">
                            <span class="block">Profit</span>                    
                            <span class="h4">$4k</span>
                            <i class="fa fa-level-down text-danger"></i>
                        </div>
                        <div class="clear">
                            <div class="sparkline inline" data-type="bar" data-height="35" data-bar-width="4" data-bar-spacing="2" data-bar-color="#fb6b5b">6,5,8,9,6,3,5</div>
                        </div>
                    </div>
                </div>-->
        </div>
    </div>

    <!-- <div class="wrapper bg-light font-bold">
        QUICK ACCESS BAR - REVIEW
       <a href="#" class="m-r"><i class="fa fa-bar-chart-o fa-2x icon-muted v-middle"></i> Analysis</a>
       <a href="#" class="m-r"><span class="badge up m-r-n bg-danger">4</span><i class="fa fa-envelope fa-2x icon-muted  v-middle"></i> Message</a>
       <a href="#" class="m-r"><i class="fa fa-calendar fa-2x icon-muted  v-middle"></i> My Calendar</a>
       <a href="#"><i class="fa fa-cog fa-2x icon-muted  v-middle"></i> Settings</a>
       
    </div>-->

</header> 
<section  class="hbox stretch">
    <aside class="aside-lg bg-light lter b-r">
        <section class="vbox">
            <section class="scrollable">
                <div class="wrapper">
                    <div class="clearfix m-b">
                        <a href="#" class="pull-left thumb m-r">
                            <?php if ($organisation['Organisation']['logo']) { ?>
                                <img src="<?php echo $this->Html->url($organisation['Organisation']['logo']); ?>" class="img-thumbnail">
                            <?php } else { ?>
                                <img src="<?php echo $this->Html->url('/img/logo_placeholder.jpg'); ?>" class="img-thumbnail">
                            <?php } ?>
                        </a>
                        <div class="clear">
                            <div class="h4 m-t-xs m-b-xs"><?php echo $organisation['Organisation']['name']; ?></div>
                            <small class="text-muted"><i class="fa fa-map-marker"></i> <?php echo $organisation['Organisation']['address']; ?></small>
                        </div>                
                    </div>

                    <div class="">
                        <?php
                        $values = array();
                        $colors = array('#9c3', '#099', '#39c', '#c33', '#609', '#319', '#444', '#ccc', '#909');
                        foreach ($stats as $stat) {
                            if ($stat['category_name'] != 'All Members') {
                                $values[] = $stat['members'];
                            }
                        }
                        ?>
                        <section class="panel">
                            <div class='panel-heading'>Membership Overview</div>
                            <div class="text-center wrapper">
                                <div class="sparkline inline" data-type="pie" data-height="80" data-slice-colors="['<?php echo implode("','", $colors); ?>']">
                                    <?php echo implode(",", $values); ?>
                                </div>
                            </div>
                            <ul class="list-group no-radius text-sm">
                                <?php
                                $count = 1;
                                foreach ($stats as $stat) {
                                    if ($stat['category_name'] != 'All Members') {
                                        ?>
                                        <li class="list-group-item">
                                            <span class="pull-right"><?php echo $stat['members']; ?></span>
                                            <span class="label" style='background-color: <?php echo $colors[$count - 1]; ?>'><?php echo $count++; ?></span>
                                            <?php echo $stat['category_name']; ?>
                                        </li>
                                        <?php
                                    }
                                }
                                ?>
                                <li class="list-group-item bg-light">
                                    <span class="pull-right"><?php echo $stats[0]['members']; ?></span>
                                    <span class="label bg-dark"><?php echo $count++; ?></span>
                                    <?php echo 'Total'; ?>
                                </li>
                            </ul>
                        </section>
                    </div>

                    <?php
                    if (isset($orgAccount['OrganisationRole']['admin_access'])) {
                        $percent = 33;
                        $percent += $tasks['profile_updated'] == 1 ? 33 : 0;
                        $percent += $tasks['accounts_created'] > 1 ? 34 : 0;

                        if ($percent < 100) {
                            ?>
                            <div class="panel wrapper">
                                <div class="text-center m-b">
                                    <div class="inline">
                                        <div class="easypiechart" data-percent="<?php echo $percent; ?>" data-line-width="15" data-track-color="#eee" data-bar-color="#afcf6f" data-scale-color="#ddd" data-loop="false" data-size="150">
                                            <span class="h2">33</span>%
                                            <div class="easypie-text">Profile<br />Completeness</div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-xs-12">
                                        <?php if ($percent < 100) { ?>
                                            <h5 class="font-bold text-primary">Remaining Tasks</h5>

                                            <div class="text-sm">
                                                <?php if ($tasks['profile_updated'] == 0) { ?>
                                                    <div class="row m-b-xs">
                                                        <div class="col-xs-1 text-right">
                                                            <i class="fa fa-angle-right"></i>
                                                        </div> 
                                                        <div class="col-xs-9">
                                                            Complete <a href="<?php echo $this->Html->url("/" . $this->params['organisationSlug'] . '/settings/general'); ?>" class="text-info">Profile</a>
                                                        </div>
                                                    </div>
                                                <?php } ?>

                                                <?php if ($tasks['accounts_created'] == 1) { ?>
                                                    <div class="row m-b-xs">
                                                        <div class="col-xs-1 text-right">
                                                            <i class="fa fa-angle-right"></i>
                                                        </div>
                                                        <div class="col-xs-9">
                                                            Create <a href="<?php echo $this->Html->url("/" . $this->params['organisationSlug'] . '/settings/accounts'); ?>" class="text-info">Staff Accounts</a>
                                                        </div>
                                                    </div>
                                                <?php } ?>
                                            </div>
                                        <?php } else { ?>
                                            <h5 class="h5 text-success font-bold text-center">Congratulation! Your profile is up to date</h5>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                            <?php
                        }
                    }
                    ?>

                </div>
            </section>
        </section>
    </aside>

    <aside class="bg-white-only">



        <header class="header bg-light bg-gradient">
            <ul class="nav nav-tabs nav-white">
                <li class="active"><a href="#tab1" data-toggle="tab"><i class="fa fa-clock-o"></i> Activity</a></li>
                <li><a href="#birthdays" data-toggle="tab"><i class="fa fa-calendar"></i> Birthdays</a></li>
            </ul>
        </header>


        <div class="tab-content">
            <div class="tab-pane active" id="tab1">
                <section class='hbox stretch'>
                    <section class='scrollable'>
                        <input type='hidden' id='join_approval_url' value='<?php echo $this->Html->url(array('action' => 'approve')); ?>'
                               <ul class="list-group m-b-none m list-group-lg list-group-sp">
                            <!-- USE FOR LOOP WHEN DATA IS AVAILABLE-->

                            <?php
                            foreach ($feed as $record) {
                                if (!isset($record["Member"]['id'])) {
                                    continue;
                                }
                                ?>
                                <li class="list-group-item">

                                    <a href="#" class="thumb-sm pull-left m-r-sm">
                                        <?php if (isset($record['OrganisationMemberImage']['MemberImage']['url']) && $record['OrganisationMemberImage']['MemberImage']['url']) { ?>
                                            <img src="<?php echo $this->Html->url($record['OrganisationMemberImage']['MemberImage']['thumb_url']); ?>" class="img-circle">
                                        <?php } else { ?>
                                            <img src="<?php echo $this->Html->url('/img/admin/no-image.gif'); ?>" class="img-circle">
                                        <?php } ?>
                                    </a>

                                    <a class="profile_link" href="<?php echo $this->Html->url(array('action' => 'member_details', $record['Member']['id'])); ?>" class="clear">
                                        <small class="pull-right">
                                            <?php
                                            $created = $record['OrganisationMember']['created'];
                                            echo $this->Time->timeAgoInWords($created, array(
                                                'accuracy' => array(
                                                    'month' => 'month',
                                                    'day' => 'day',
                                                    'week' => 'weeks'
                                                )
                                            ));
                                            ?>
                                        </small>
                                        <strong class="block"><?php echo $record['Member']['first_name'] . ' ' . $record['Member']['last_name']; ?></strong>
                                        <small class='muted'>
                                            <?php
                                            switch ($record['OrganisationMember']['source']) {
                                                case 'admin':
                                                    echo "Profile created by " . $record['Approver']['first_name'] . ' ' . $record['Approver']['last_name'];
                                                    break;

                                                case 'public':
                                                    if ($record['OrganisationMember']['approved'] == 1) {
                                                        echo 'Join request approved by ' . $record['Approver']['first_name'] . ' ' . $record['Approver']['last_name'];
                                                    } else {
                                                        echo "Asked to join organisation.";

                                                        echo "<span class='pull-right'>";
                                                        echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-success' data-member-id='{$record['Member']['id']}' data-action='approve'><i class='fa fa-check'></i> Approve</button>";
                                                        echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-danger' data-member-id='{$record['Member']['id']}' data-action='decline'><i class='fa fa-times'></i> Decline</button>";
                                                        echo "</span>";
                                                    }
                                                    break;

                                                case 'registration':
                                                    if ($record['OrganisationMember']['approved'] == 1) {
                                                        echo 'Registration approved by ' . $record['Approver']['first_name'] . ' ' . $record['Approver']['last_name'];
                                                    } else {
                                                        echo "Registered with organisation.";

                                                        echo "<span class='pull-right'>";
                                                        echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-success' data-member-id='{$record['Member']['id']}' data-action='approve'><i class='fa fa-check'></i> Approve</button>";
                                                        echo "<button href='#' class='approve_btn m-r-xs btn btn-xs btn-danger' data-member-id='{$record['Member']['id']}' data-action='decline'><i class='fa fa-times'></i> Decline</button>";
                                                        echo "</span>";
                                                    }
                                                    break;

                                                default:
                                                    echo "Membership created";
                                                    break;
                                            }
                                            ?>
                                        </small>
                                    </a>
                                </li>
                            <?php } ?>
                        </ul>
                    </section>
                </section>
            </div>  

            <div class="tab-pane" id="birthdays">
                <!-- TODO Add something eventful -->
            </div>

            <div class="tab-pane" id="tab2">
                <!-- TODO Add something eventful -->
            </div>
        </div> 
    </aside>

    <aside class="bg-white">
        <section class="vbox">
            <div class="scrollable">
                <div class="wrapper">

                    <div class="col-md-12">
                        <div class='panel'>
                            <div class='panel-heading'>
                                <div class="row">
                                    <div class="col-md-4 p-t-xs">
                                        Quick Statistics
                                    </div>

                                    <div class="col-md-8">
                                        <select id="group-chart-select" class="form-control input-s input-sm">
                                            <?php foreach ($general_stats as $label => $group_stats) { ?>
                                                <optgroup label="<?php echo $label; ?>"> <?php
                                                    foreach ($group_stats as $key => $data) {
                                                        $id = strtolower(str_replace(" ", "_", $key));
                                                        ?>
                                                        <option value="<?php echo "#tab_$id"; ?>"><?php echo $key; ?></option>
                                                    <?php } ?>
                                                </optgroup> 
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class='panel-body'>
                                <div id='group-charts' role="tabpanel" class='p-l'>
                                    <!-- Tab panes -->
                                    <div style='height: 200px;'>
                                        <?php
                                        foreach($general_stats as $label => $group_stats) {
                                        foreach ($group_stats as $key => $data) {
                                            $id = strtolower(str_replace(" ", "_", $key));
                                            ?>
                                            <div class='tab-pane hidden' id="<?php echo "tab_$id"; ?>" style='height: 200px;'>
                                                <?php echo json_encode($data); ?>
                                            </div>
                                        <?php }
                                        } ?>
                                    </div>
                                </div>
                            </div>
                            <div class='panel-footer text-xs font-bold'>
                                Charts represent the state of current data provided and may not reflect the true representation of your organisation.
                            </div>
                        </div>

                    </div>

                    <div class="col-md-12">
                        <section class="panel">
                            <header class="panel-heading font-bold">New Membership Registrations</header>
                            <div class="panel-body">
                                <div id="flot-chart-members"  style="height:180px"></div>
                            </div>                  
                        </section>
                    </div>

                </div>
            </div>
        </section>
    </aside>
</section>

<input type="hidden" id="charts-data-url" value="<?php echo $this->Html->url(array('controller' => 'charts', 'action' => 'member_stats')); ?>" />
<input type="hidden" id="birthdays-data-url" value="<?php echo $this->Html->url(array('controller' => 'organisation', 'action' => 'birthdays')); ?>" />

<?php
echo $this->Html->script('charts/flot/jquery.flot.min.js');
echo $this->Html->script('charts/flot/jquery.flot.tooltip.min.js');
echo $this->Html->script('charts/flot/jquery.flot.resize.js');
echo $this->Html->script('charts/flot/jquery.flot.orderBars.js');
echo $this->Html->script('charts/flot/jquery.flot.pie.min.js');
echo $this->Html->script('charts/flot/jquery.flot.time.js');

echo $this->Html->script('app/views/organisations/dashboard/birthdays.js');
echo $this->Html->script('app/views/organisations/dashboard/charts.js');
echo $this->Html->script('app/views/organisations/dashboard/feed.js');
